package com.qf.test.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.test.mapper.DtsPermissionMapper;
import com.qf.test.pojo.DtsPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
@Service
public class PermissionServiceImpl implements PermissionService {

   @Autowired
   private DtsPermissionMapper permissionMapper;
    @Override
    public Set<String> queryPermissonByRoleIds(Integer[] ids) {
       //判断ids如果为空 返回空的set集合
        if(ids==null||ids.length==0){
            return new HashSet<String>();
        }
        //创建并设置查询条件
        QueryWrapper<DtsPermission> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("role_id",ids);
        queryWrapper.eq("deleted",false);
        //查询结果并返回
        List<DtsPermission> list = permissionMapper.selectList(queryWrapper);
        //将list换成set
        HashSet<String> permSet = new HashSet<>();
        if(list!=null){
            for (DtsPermission permission : list) {
                permSet.add(permission.getPermission());
            }
        }
        return permSet;
    }
}
